<?php

class recordset
{
	private $_model;
	private $_parentRecord;

	private $_newRecords = array();

	public function __construct($model)
	{
		$this->setModel($model);
	}
	
	public function __call($name, $arguments=array())
	{
		if (($name=='new' . ucfirst($this->getModel()->modelName)) && ($this->getParentRecord()))
		{
			// create new record using the parentRecords relation data.
			
			foreach($this->getParentRecord()->getModel()->relations as $as=>$relation)
			{
				if(($relation['type']=='many') && ($relation['model']==$this->getModel()->modelName))
				{
					$arguments[0][$relation['foreign']] = $this->getParentRecord()->{$relation['local']};
				}
			}
			
			$newRecord = $this->getModel()->constructRecord($arguments[0]);
			$this->_newRecords[] = $newRecord;
			
			return $newRecord;
		}
	}
	
	public function getModel()
	{
		return $this->_model;
	}
	
	public function setModel($model)
	{
		$this->_model = $model;
		return $this->_model;
	}
	
	public function getParentRecord()
	{
		return $this->_parentRecord;
	}
	
	public function setParentRecord($parentRecord)
	{
		$this->_parentRecord = $parentRecord;
		return $this->_parentRecord;
	}
	
	public function save()
	{
		foreach($this as $key=>$record)
		{
			$record->save();
		}
	}
	
	public function __get($value)
	{
		
	}
	
}

?>